<template>
    <div class="content">
        
        <el-table :data="tableData" border v-loading="form.loading" style="width: 100%;font-size: 16px;">
            <el-table-column type="index" :index="indexMethod" label="序号" width="60" align="center" />
            <el-table-column label="所属项目" show-overflow-tooltip align="center">
                <template #default="scope">
                    <el-text>{{scope.row.project.title}}</el-text>
                </template>
            </el-table-column>
            <el-table-column prop="name" label="甲方名称" show-overflow-tooltip align="center" />
            <el-table-column prop="tax_id" label="甲方税号" show-overflow-tooltip align="center" />
            <el-table-column prop="mobile" label="甲方联系电话" show-overflow-tooltip align="center" />
            <el-table-column prop="invoice_amount" label="开票金额" show-overflow-tooltip  align="center" />
            <el-table-column prop="bank_account" label="甲方银行账号" show-overflow-tooltip align="center"  />
            <el-table-column prop="invoice_type" label="发票类型" show-overflow-tooltip align="center" />
            <el-table-column label="申请日期" show-overflow-tooltip align="center">
                <template #default="scope">
                    <el-text v-if="scope.row.application">{{scope.row.application.created_at}}</el-text>
                </template>
            </el-table-column>
            <el-table-column label="申请状态" show-overflow-tooltip align="center">
                <template #default="scope">
                    <el-text type="primary" v-if="scope.row.application" class="cp">{{scope.row.application.status_text}}</el-text>
                </template>
            </el-table-column>
            <el-table-column fixed="right" label="操作" width="80" align="center">
                    <template #default="scope">
                        <el-button v-if="scope.row.application.status == 'pending'" link type="primary" @click="onEdit(scope.row.id)" size="small">审批</el-button>
                    </template>
                </el-table-column>
        </el-table>
    </div>

    <el-dialog v-model="isEdit" title="审核操作" width="30%">
        <component :is="invoiceForm" :data = editId @onSave="onSave" />
    </el-dialog>
</template>

<script lang="ts" setup>
import { ref,onMounted } from 'vue'
import http from '../../../util/request';
import invoiceForm from './components/invoiceForm.vue';
const indexMethod = (index: number) => {
  return index+= 1
}
const form = ref<any>({search:'',page:0,type_id:0,current:0,total:10,limit:20,loading:false,parentBorder:false})
const isEdit = ref<boolean>(false)
const editId = ref<number>(0)
const tableData = ref<any>([])

const onGetData = () => {
    form.value.loading = true
    http.post('/projectInvoice',form.value).then((response:any)=>{
        form.value.loading = false
        tableData.value = response.data.data
    })
}

const onEdit = (id: number) => {
    editId.value = id
    isEdit.value = true
}

onMounted(()=>{
    onGetData()
})

const onSave = () => {
    isEdit.value = false
    onGetData()
}
</script>

<style scoped>

</style>